//
//  ResposeModel.swift
//  StoreProject
//
//  Created by CYC on 1998/1/5.
//

import UIKit
import HandyJSON
import GRDB


// MARK:======================================基础========================================
// MARK:所有网络请求的头部
class ResposeModel: HandyJSON {

    var status: String?       // 200 成功
    var result: String?


    var code: String?       // 200 成功
    var message: String?
    var data: String?
        
    required init() {
        
    }
}

// MARK:年
class YearModel: HandyJSON {

    var year = Int(0)
    var monthList = [MonthModel]()
    
    // 干支纪年
    var chineseYear: String {
        
        // 天干：甲 乙 丙 丁 戊 己 庚 辛 壬 癸
        //      4、5、6、7、8、9、0、1、2、3
        
        // 地支：子 丑 寅 卯 辰 巳 午  未  申 酉 戌 亥
        //      4、5、6、7、8、9、10、11、0、1、2、3
        
        // 生肖：鼠 牛 虎 兔 龙 蛇 马  羊  猴 鸡 狗 猪
        //      4、5、6、7、8、9、10、11、0、1、2、3
        
        
        
        // 公元年除以10得到的余数对应天干，除以12得到的余数对应地支
        
        let list1 = ["庚",  "辛",  "壬",  "癸",  "甲",  "乙",  "丙",  "丁",  "戊",  "己"]
        let list2 = ["申",  "酉",  "戌",  "亥",  "子",  "丑",  "寅",  "卯",  "辰",  "巳",  "午",  "未"]
        let list3 = ["猴",  "鸡",  "狗",  "猪",  "鼠",  "牛",  "虎",  "兔",  "龙",  "蛇",  "马",  "羊"]
        let text1 = list1[self.year % 10]
        let text2 = list2[self.year % 12]
        let text3 = list3[self.year % 12]
        
        return String.init(format: "%@%@%@年", text1, text2, text3)
        
    }
    
    required init() {
        
    }
}

// MARK:月
class MonthModel: HandyJSON {

    var year = Int(0)
    var month = Int(0)
    var dayList = [DayModel]()
        
    required init() {
        
    }
}

// MARK:日
class DayModel: HandyJSON {

    var day = Int(0)
    var date = DateComponents()     //  weekday 周日为1，一次类推
  
    
    // 农历 2020年冬月廿二
    var chineseDay: String {
        
        // 公历转农历
        var com = DateComponents()
        let solarCalendar = Calendar.init(identifier: .gregorian)
        com.year = self.date.year
        com.month = self.date.month
        com.day = self.date.day
        com.hour = 12
        com.minute = 0
        com.second = 0
        com.timeZone = TimeZone.init(secondsFromGMT: 60 * 60 * 8)
        let solarDate = solarCalendar.date(from: com)
        
        let lunarCalendar = Calendar.init(identifier: .chinese)
        let formatter = DateFormatter()
        formatter.locale = Locale(identifier: "zh_CN")
        formatter.dateStyle = .medium
        formatter.calendar = lunarCalendar
        return formatter.string(from: solarDate!)
        
    }
    
    // 初一
    var chineseSubDay: String {
        
        let text1 = self.chineseDay as NSString
        let text2 = text1.substring(with: NSRange.init(location: text1.length - 2, length: 2))
        return text2
    }
    
    // 月份
    var chineseSubMonth: String {
        
        let text1 = self.chineseDay as NSString
        let text2 = text1.substring(with: NSRange.init(location: text1.length - 4, length: 2))
        return text2
    }
    
    // 特殊日子
    var specialDay: String {
        
        var text = ""
        
        if self.date.month == 1 && self.date.day == 1  {
            text = "元旦"
        }

        if self.chineseDay.hasSuffix("正月初一") == true {
            text = "春节"
        }
        
        if self.date.month == 4 && self.date.day == 5  {
            text = "清明"     // 其实是4月 4、5、6 之一
        }
        
        if self.date.month == 5 && self.date.day == 1  {
            text = "劳动节"
        }
        
        if self.chineseDay.hasSuffix("五月初五") == true {
            text = "端午"
        }
        
        if self.chineseDay.hasSuffix("八月十五") == true {
            text = "中秋"
        }
        
        if self.date.month == 10 && self.date.day == 1  {
            text = "国庆"
        }
        
        
        return text
    }
        
    required init() {
        
    }
}


// MARK:详情位移
class DetailOffestModel: HandyJSON {

    var offestStartY = CGFloat(0)   // 区间起点
    var offestEndY = CGFloat(0)     // 区间终点
    var month = MonthModel()        // 对应的月份
        
    required init() {
        
    }
}
